package xutil

import (
	"encoding/base64"
	"errors"
	"io"
	"net/http"
	"time"
)

func F图片地址转base64(path string) (baseImg string, err error) {
	client := &http.Client{
		Timeout: time.Second * 5, //超时时间
	}
	var bodyImg io.Reader
	request, err := http.NewRequest("GET", path, bodyImg)
	if err != nil {
		err = errors.New("获取网络图片失败")
		return
	}
	respImg, err := client.Do(request)
	if err != nil {
		return
	}
	defer respImg.Body.Close()
	imgByte, err := io.ReadAll(respImg.Body)
	if err != nil {
		return
	}
	baseImg = base64.StdEncoding.EncodeToString(imgByte)
	return
}
